﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using Common;
using Domain.Common;
using Domain.Map;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Color = Microsoft.Xna.Framework.Color;
using Point = Microsoft.Xna.Framework.Point;
using Rectangle = Microsoft.Xna.Framework.Rectangle;

namespace MapComponentSprite
{
    /// <summary>
    /// 建筑物标题名称
    /// </summary>
    public class BuildingNameSprite:AutomatedSprite
    {

        public override void Draw(GameTime gameTime)
        {
            if (this.Image != null)//解决地图跳转功能，图像为空异常
            SpriteBatch.Draw(Image, DrawPosition, null,Color.White, 0, Vector2.Zero, SpriteEffects.None, 0.79996f);
        }

        public void Update(GameTime gameTime, Point cityPosition, string numberName)
        {
            LoadNamePic(numberName);
            Rectangle rectangle = new Rectangle();
            rectangle.X = cityPosition.X + (MapUnit.Width / 2) - (Image.Width / 2);
            rectangle.Y = cityPosition.Y + (MapUnit.Height / 2) - (Image.Height / 2);
            rectangle.Width = Image.Width;
            rectangle.Height = Image.Height;
            DrawPosition = rectangle;
        }
        private void LoadNamePic(string numberName)
        {
            if (this.Image == null)
                this.Image = Game.Content.Load<Texture2D>(@"Images\buildings\name\" + numberName);
        }
    }
}
